package com.lottery.game.websocket.config;

import com.lottery.game.websocket.MyHandler;
import com.lottery.game.websocket.MyHandshakeInterceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebMvc
@EnableWebSocket
public class WebSocketConfig extends WebMvcConfigurationSupport implements WebSocketConfigurer {
	private static final long heartbeatTime =  60000L; // 1 minute
	/**
	 * 前端请求路径配置类
	 */
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {


    	//添加handler
    	registry.addHandler(myHandler(), "/websocket").setAllowedOrigins("*").addInterceptors(new MyHandshakeInterceptor());
    }

    @Bean
    public WebSocketHandler myHandler() {
        return new MyHandler();
    }

}
